package com.hotel.room.controller;


import cn.hutool.core.convert.NumberWithFormat;
import com.hotel.common.config.SystemConfig;
import com.hotel.common.param.UserRoomRate;
import com.hotel.common.util.JwtUtil;
import com.hotel.common.vo.R;
import com.hotel.room.service.HotelRoomRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author trc
 * @since 2024-06-22
 */
@RestController
@RequestMapping("/hotel/roomRate")
public class HotelRoomRateController {

    @Autowired
    private HotelRoomRateService hotelRoomRateService;

    @RequestMapping("/show")
    public R showUserRoomRate(HttpServletRequest request, @RequestBody UserRoomRate userRoomRate) {

        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        Integer userId = ((NumberWithFormat) JwtUtil.parseToken(token, "id")).intValue();
        return hotelRoomRateService.showUserRoomRate(userId, userRoomRate);

    }

    @RequestMapping("/change")
    public R changeUserRoomRate(HttpServletRequest request, @RequestBody UserRoomRate userRoomRate) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        Integer userId = ((NumberWithFormat) JwtUtil.parseToken(token, "id")).intValue();
        return hotelRoomRateService.changeUserRoomRate(userId, userRoomRate);
    }

}

